package org.apache.flink.client.deployment;

import org.apache.flink.client.cluster.ClusterClientProvider;
import org.apache.flink.util.ERException;

/**
 * A descriptor to deploy a cluster (e.g. Yarn) and return a Client for Cluster communication.
 *
 * @param <T> Type of the cluster id
 */
public interface ClusterDescriptor<T> extends AutoCloseable {

    /**
     * Returns a String containing details about the cluster (NodeManagers, available memory, ...).
     */
    String getClusterDescription();

    /**
     * Retrieves an existing Flink Cluster.
     *
     * @param clusterId The unique identifier of the running cluster
     * @return Client for the cluster
     * @throws ClusterRetrieveException if the cluster client could not be retrieved
     */
    ClusterClientProvider<T> retrieve(T clusterId) throws ClusterRetrieveException;

    /**
     * Triggers deployment of a cluster.
     *
     * @param clusterSpecification Cluster specification defining the cluster to deploy
     * @return Client for the cluster
     * @throws ClusterDeploymentException if the cluster could not be deployed
     */
    ClusterClientProvider<T> deployCluster(ClusterSpecification clusterSpecification)
            throws ClusterDeploymentException;

    /**
     * Terminates the cluster with the given cluster id.
     *
     * @param clusterId identifying the cluster to shut down
     * @throws ERException if the cluster could not be terminated
     */
    void killCluster(T clusterId) throws ERException;

    @Override
    void close();
}
